<?php
/**
 * Created by PhpStorm.
 * User: czw
 * Date: 2018/7/11
 * Time: 14:59
 */
namespace app\common\model;

use app\lib\exception\BaseException;
use think\Model;

class User extends Model
{
    /**
     * 新增用户
     * @param $data
     * @return false|int
     */
    public static function createOne($data){
        $model = new self();
        $user = $model->where(['openid'=>$data['openid']])->find();
        if($user)
            throw new BaseException(['msg'=>'用户已存在！','errorCode'=>60003]);
        return $model->allowField(true)->save($data);
    }
    public static function getByOpenId($openid){
        return self::where(['openid'=>$openid])->find();
    }
    public static function getAll(){
        return self::select();
    }
    public static function updateOne(){

    }
    public static function deleteOne(){

    }
}